﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using KZ.Exception;
using KZ.Lottery.BLL;
using KZ.Lottery.Entities;
using KZ.Lottery.Resources;
using KZ.Utilities;

namespace KZ.Lottery
{
    public partial class FrmRuleDetailGroup : Form
    {
        #region Private Variables

        decimal _FirstDay;
        List<GroupValue> _GroupValueList;

        #endregion Private Variables

        #region Private Methods

        private void FrmRuleDetailGroup_Load(object sender, EventArgs e)
        {
            _GroupValueList = new List<GroupValue>();

            LoadSettingValue();
            LoadGroupValue();
            LoadRuleDetail();
        }

        private void LoadRuleDetail()
        {
            try
            {
                List<RuleDetail> ruleDetailList = RuleDetailBLL.GetRuleDetailList(RuleID);
                foreach (RuleDetail item in ruleDetailList)
                {
                    TabPage tabPage = new TabPage(item.Line.ToString());
                    ucRuleDetailGroup uc = new ucRuleDetailGroup
                    {
                        RuleDetailID = item.RuleDetailID,
                        GroupValueList = _GroupValueList,
                        FirstDay = _FirstDay,
                        Dock = DockStyle.Fill 
                    };

                    tabPage.Controls.Add(uc);
                    tabControl1.TabPages.Add(tabPage);
                    tabPage.Text = uc.HeaderText;
                }
            }
            catch (DataAccessException ex)
            {
                Global.SetMessage(lblMessage, ex.Message, false);
            }
            catch (System.Exception ex)
            {
                Log.LogEx("LoadRuleDetail", ex);
                Global.SetMessage(lblMessage, KZ_Message.BLM_ERR_GENERAL, false);
            }
        }

        private void LoadSettingValue()
        {
            try
            {
                SettingValue settingValue = SettingValueBLL.GetSettingValueFirstDay();
                _FirstDay = settingValue.Value;
            }
            catch (DataAccessException ex)
            {
                Global.SetMessage(lblMessage, ex.Message, false);
            }
            catch (System.Exception ex)
            {
                Log.LogEx("LoadSettingValue", ex);
                Global.SetMessage(lblMessage, KZ_Message.BLM_ERR_GENERAL, false);
            }
        }

        private void LoadGroupValue()
        {
            try
            {
                _GroupValueList = GroupValueBLL.GetGroupValueList();
            }
            catch (DataAccessException ex)
            {
                Global.SetMessage(lblMessage, ex.Message, false);
            }
            catch (System.Exception ex)
            {
                Log.LogEx("LoadGroupValue", ex);
                Global.SetMessage(lblMessage, KZ_Message.BLM_ERR_GENERAL, false);
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            //_HeadValueList.Clear();
            //_TailValueList.Clear();
            //_HeadFirstValueList.Clear();
            //_TailFirstValueList.Clear();

            //_IsHeadLoaded = false;
            //_IsTailLoaded = false;
        }

        #endregion Private Methods

        #region Constructors

        public FrmRuleDetailGroup()
        {
            InitializeComponent();
        }

        #endregion Constructors

        #region Public Members

        public string RuleID { get; set; }

        #endregion Public Members
    }
}